package com.tv.enoguia.Utils;

import com.tv.enoguia.R;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
import android.widget.CompoundButton;
import android.widget.ImageButton;

public class TabIcon extends ImageButton {

	public TabIcon(Context context) {
		this(context, null);
	}

	public TabIcon(Context context, AttributeSet attributeset) {
		this(context, attributeset, 0);
	}

	public TabIcon(Context context, AttributeSet attributeset, int i) {
		super(context, attributeset, i);
		setPadding(2, 2, 2, 2);
		setScaleType(ScaleType.CENTER_INSIDE);
		setBackgroundResource(android.R.color.transparent);
	}
	
	Boolean checked = false;
	
	Boolean isChecked() {
		return checked;
	}

	private void updateState() {
		Drawable drawable = getDrawable();
		if(drawable==null) {
			Log.e("Tuan", "Null me no roi");
			return;
		}
		if (isChecked()) {
			drawable.setColorFilter(Color.parseColor("#C90011"), android.graphics.PorterDuff.Mode.SRC_ATOP);
		} else {
			drawable.setColorFilter(null);
		}
		invalidate();
	}

	protected void onMeasure(int i, int j) {
		super.onMeasure(i, j);
		//setTextSize(0,(3 * Math.min(getMeasuredWidth(), getMeasuredHeight())) / 4);
		super.onMeasure(i, j);
	}

	public void setChecked(boolean flag) {
		checked = flag;
		updateState();
	}
}
